package com.gitee.W_Jun.methods;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-25 15:12
 * @Description 虚方法与非虚方法
 *
 */
class Father {
    public Father() {
        System.out.println("father的构造器");
    }

    public static void showStatic(String str) {
        System.out.println("father " + str);
    }

    public final void showFinal() {
        System.out.println("father show final");
    }

    public void showCommon() {
        System.out.println("father普通方法");
    }
}
public class Son extends Father {
    public Son() {
        super();//invokespecial
    }

    public Son(int age) {
        this();//invokespecial
    }

    //不是重写的父类的静态方法，因为静态方法不能被重写！
    public static void showStatic(String str) {
        System.out.println("son " + str);
    }

    private void showPrivate(String str) {
        System.out.println("son private" + str);
    }

    public void show() {
        showStatic("gitee.com/W_Jun");//invokestatic
        super.showStatic("good!");//invokestatic
        showPrivate("hello!");//invokespecial
        super.showCommon();//invokespecial

        showFinal();//invokevirtual 虽然叫invokevirtual，但并不是一个虚方法，而是非虚方法，因为有final修饰
        super.showFinal();//invokespecial
        showCommon();//invokevirtual
        info();//invokevirtual

        MethodInterface in = null;
        in.methodA();//invokeinterface
    }

    public void info() {

    }

    public void display(Father f) {
        f.showCommon();
    }

    public static void main(String[] args) {
        Son so = new Son();
        so.show();
    }
}

interface MethodInterface{
    void methodA();
}